# -*- coding: utf-8 -*-
# @Time    : 2020/9/14 12:25
# @Author  : liuwenfan
# @File    : group_service.py
# @Software: PyCharm
from sqlalchemy import desc

from application import db
from application.models.mantis_models import MantisProjectVersionTable


def get_project_version(project_id):
    # sql = "select p.id,p.name " \
    #       "from mantis_project_table as p,mantis_project_hierarchy_table as h " \
    #       "where p.id = h.child_id and h.parent_id=%s"
    ret = db.session.query(MantisProjectVersionTable.id, MantisProjectVersionTable.version).filter(
        MantisProjectVersionTable.project_id == project_id).order_by(desc(MantisProjectVersionTable.date_order)).all()
    data = [{"project_version_id": i, "project_version_name": j} for i, j in ret]
    return data
